package com.xinlu.common.exception;

import java.util.List;

import org.apache.log4j.Priority;

/**
 * 框架异常的底层类，让子类实现getExceptionLevel和getCurrentPageShow方法。
 * 
 * <li><b><code>getExceptionLevel()</code>方法</b></li>
 * 用于得到该异常的错误级别，日志输出时候使用
 * <p />
 * <li><b><code>getCurrentPageShow</code></b></li>
 * 这个异常是否要在当前页面进行显示。true为在当前页面显示，false为在错误页面进行实现.
 */
public abstract class CommonException extends RuntimeException {
	
	/**
	 * 资源文件里的name
	 */
	private String errCode;
	
	private String arg;
	
	private String[] args;
	
	private String msgparamid = null;

	public CommonException() {
		super();
	}
	
	public CommonException(String errCode) {
		super(errCode);
	}
	
	/**
	 * Construct function
	 */
	public CommonException(String errCode, List<String> errorList) {
		super(errCode);
		this.args = (String[]) errorList.toArray();
	}


	public CommonException(String message, Throwable cause) {
		super(message, cause);
	}

	

	public CommonException(Throwable cause) {
		super(cause);
	}
	
	/**
	 * Construct function
	 * 
	 * @param errCode
	 * @param e
	 * @param args
	 */
	public CommonException(String errCode, Throwable e, String[] args) {
		super(errCode, e);
		setArgs(args);
	}

	/**
	 * Construct function
	 * 
	 * @param errCode
	 * @param args
	 */
	public CommonException(String errCode, String[] args) {
		super(errCode);
		setArgs(args);
	}

	/**
	 * Construct function
	 * 
	 * @param errCode
	 * @param e
	 * @param args
	 */
	public CommonException(String errCode, Throwable e, String arg) {
		super(errCode, e);
		setArg(arg);
	}

	/**
	 * Construct function
	 * 
	 * @param errCode
	 * @param args
	 */
	public CommonException(String errCode, String arg) {
		super(errCode);
		setArg(arg);
	}
	
	/**
	 * @return Returns the errCode.
	 */
	public String getErrCode() {
		return errCode;
	}

	/**
	 * @param errCode
	 *            The errCode to set.
	 */
	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}

	/**
	 * @return Returns the arg.
	 */
	public String getArg() {
		return arg;
	}

	/**
	 * @param arg
	 *            The arg to set.
	 */
	public void setArg(String arg) {
		this.arg = arg;
	}

	/**
	 * @return Returns the args.
	 */
	public String[] getArgs() {
		if (arg != null) {
			return new String[] { arg };
		} else {
			return args;
		}
	}

	/**
	 * @param args
	 *            The args to set.
	 */
	public void setArgs(String[] args) {
		this.args = args;
	}

	/**
	 * @return Returns the msgparamid.
	 */
	public String getMsgparamid() {
		return msgparamid;
	}

	/**
	 * @param msgparamid
	 *            The msgparamid to set.
	 */
	public void setMsgparamid(String msgparamid) {
		this.msgparamid = msgparamid;
	}

	/**
	 * 
	 * function: 得到子类异常等级(Priority的枚举对象)
	 * 
	 * @return
	 * 
	 * @author Rain Stars Aug 4, 2009 3:38:33 PM
	 */
	public abstract Priority getExceptionLevel();

	/**
	 * 
	 * function: 得到该异常是否在当前页面显示（true为当前页面显示，false为否）
	 * 
	 * @return
	 * 
	 * @author Rain Stars Aug 4, 2009 3:38:43 PM
	 */
	public abstract boolean getCurrentPageShow();
	
	
	
}
